package cn.juque.common.base;

import cn.juque.common.constants.MessageEnum;
import cn.juque.common.exception.AppException;
import lombok.Data;

import java.io.Serializable;

/**
 * @author nuoka
 * @date 2019-11-10
 */
@Data
public class BaseResponseDTO<T> implements Serializable {

    private static final long serialVersionUID = 2731956276393414104L;

    private String code;

    private String msg;

    private T data;

    private PageInfo pageInfo;

    public BaseResponseDTO() {

    }

    public BaseResponseDTO(AppException e, T data) {
        this(e.getCode(), e.getMessage(), data);
    }

    public BaseResponseDTO(String code, String msg) {
        this(code, msg, null);
    }

    public BaseResponseDTO(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public BaseResponseDTO(String code, String msg, T data, PageInfo pageInfo) {
        this(code, msg, data);
        this.pageInfo = pageInfo;
    }

    public BaseResponseDTO(MessageEnum msg, T data) {
        this(msg.getCode(), msg.getMsg(), data);
        this.pageInfo = null;
    }

    public BaseResponseDTO(MessageEnum msg, T data, PageInfo pageInfo) {
        this(msg, data);
        this.pageInfo = pageInfo;
    }
}
